package com.yf.controller.admin.article;

import java.util.List;
import java.util.Map;

import com.yf.vo.TicketBackVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yf.annotation.SysLog;
import com.yf.entity.TicketEntity;
import com.yf.service.article.TicketService;
import com.yf.response.R;
import com.yf.consts.DaoConst;


/**
 * 投票Controller
 *
 * @author hxf
 * @email 505860922@qq.com
 * @date Wed Aug 22 14:30:08 CST 2018
 */
@RestController
@RequestMapping("/ticket")
public class TicketController {
    @Autowired
    private TicketService ticketService;

    /**
     * 列表投票
     */
    @RequestMapping("/list")
    @RequiresPermissions("ticket:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageHelper.startPage(DaoConst.getPage(params),DaoConst.getLIMIT(params));
        List<TicketEntity> ticketList = ticketService.queryList(params);
        return R.ok(new PageInfo(ticketList));
    }

    /**
     * 查看投票
     */
    @SysLog("查看投票")
    @RequestMapping("/info/{id}")
    @RequiresPermissions("ticket:info")
    public R info(@PathVariable("id") Long id) {
        TicketEntity ticket = ticketService.get(id);

        return R.ok(ticket);
    }

    /**
     * 保存投票
     */
    @SysLog("保存投票")
    @RequestMapping("/save")
    @RequiresPermissions("ticket:save")
    public R save(TicketEntity ticket) {
        ticketService.save(ticket);

        return R.ok(ticket);
    }

    /**
     * 修改投票
     */
    @SysLog("修改投票")
    @RequestMapping("/update")
    @RequiresPermissions("ticket:update")
    public R update(TicketEntity ticket) {
        ticketService.update(ticket);

        return R.ok(ticket);
    }

    /**
     * 删除投票
     */
    @SysLog("删除投票")
    @RequestMapping("/delete")
    @RequiresPermissions("ticket:delete")
    public R delete(@RequestBody Long[]ids) {
        ticketService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 所有投票
     */
    @SysLog("所有投票")
    @RequestMapping("/queryAll")
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<TicketEntity> ticketList = ticketService.queryList(params);

        return R.ok(ticketList);
    }

    /***********自定义开始***********/

    /**
     * back 投票记录
     */
    @RequestMapping("/ticketRecord")
    public R findTicketRecord(@RequestParam Map<String, Object> params) {
        PageHelper.startPage(DaoConst.getPage(params),DaoConst.getLIMIT(params));
        List<TicketBackVo> list = ticketService.findTicketRecord(params);
        return R.ok(new PageInfo(list));
    }

}
